# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

import sys
from PyQt5.QtWidgets import *
from PyQt5.Qt import *
from PyQt5.QtGui import *


class Bar(QWidget):
    def __init__(self):
        super(Bar, self).__init__()
        self.InitUI()

    def InitUI(self):
        layout = QHBoxLayout()
        self.l1 = QLabel("拖动滑块变化颜色")
        self.l1.setFont(QFont("微软雅黑",16))
        layout.addWidget(self.l1)

        self.b1 = QScrollBar()
        self.b1.setMaximum(255)
        self.b1.sliderMoved.connect(self.slider)
        layout.addWidget(self.b1)

        self.b2 = QScrollBar()
        self.b2.setMaximum(255)
        self.b2.sliderMoved.connect(self.slider)
        layout.addWidget(self.b2)

        self.b3 = QScrollBar()
        self.b3.setMaximum(255)
        self.b3.sliderMoved.connect(self.slider)
        layout.addWidget(self.b3)

        self.setGeometry(300,300,300,300)
        self.setLayout(layout)

    def slider(self):
        # 实例化调色板
        palette = QPalette()
        # 获滑块滑动的值
        color = QColor(self.b1.value(),self.b2.value(),self.b3.value(),255)
        # 设置获取到的颜色值
        palette.setColor(QPalette.Foreground,color)
        # 设置写入值
        self.l1.setPalette(palette)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    bar = Bar()
    bar.show()
    sys.exit(app.exec_())